//! 特性功能演示程序
//! 
//! 展示如何使用不同特性组合的 librarys 库功能

fn main() {
    println!("=== Rust 快速开发工具类库 - 特性演示 ===\n");
    
    // 核心功能 (总是可用)
    demo_core_features();
    
    // 日期时间功能
    #[cfg(feature = "datetime")]
    demo_datetime_features();
    
    // 验证功能
    #[cfg(feature = "validation")]
    demo_validation_features();
    
    // 加密功能
    #[cfg(feature = "crypto")]
    demo_crypto_features();
    
    // 数据处理功能
    #[cfg(feature = "data")]
    demo_data_features();
    
    // 随机生成功能
    #[cfg(feature = "random")]
    demo_random_features();
    
    // IO功能
    #[cfg(feature = "io")]
    demo_io_features();
    
    // 网络功能
    #[cfg(feature = "network")]
    demo_network_features();
    
    println!("\n=== 演示完成 ===");
}

fn demo_core_features() {
    println!("【核心功能演示】");
    
    use librarys::core::string_utils;
    
    // 字符串基本判断
    println!("is_empty(''): {}", string_utils::is_empty(""));
    println!("is_not_empty('hello'): {}", string_utils::is_not_empty("hello"));
    println!("is_chinese_char('你'): {}", string_utils::is_chinese_char('你'));
    
    // 类型转换
    println!("to_int('123'): {}", string_utils::to_int("123"));
    println!("to_double('3.14'): {}", string_utils::to_double("3.14"));
    
    // 大小写转换
    println!("to_uppercase_first('hello'): {}", string_utils::to_uppercase_first("hello"));
    println!("to_lowercase_first('WORLD'): {}", string_utils::to_lowercase_first("WORLD"));
    
    // 命名风格转换
    println!("camel_case_to_underscore('userName'): {}", string_utils::camel_case_to_underscore("userName"));
    println!("underscore_to_camel_case('user_name'): {}", string_utils::underscore_to_camel_case("user_name"));
    
    // 字符串处理
    println!("contains_chinese('hello世界'): {}", string_utils::contains_chinese("hello世界"));
    println!("is_garbled('正常文本'): {}", string_utils::is_garbled("正常文本"));
    
    println!();
}

#[cfg(feature = "datetime")]
fn demo_datetime_features() {
    println!("【日期时间功能演示】");
    
    use librarys::datetime::date_utils;
    
    // 当前时间
    println!("当前时间戳: {}", date_utils::current_timestamp());
    println!("当前毫秒时间戳: {}", date_utils::current_timestamp_millis());
    
    // 闰年判断
    println!("2024年是闰年: {}", date_utils::is_leap_year(2024));
    println!("2023年是闰年: {}", date_utils::is_leap_year(2023));
    
    // 生肖和星座
    println!("2024年生肖: {}", date_utils::get_chinese_zodiac(2024));
    let zodiac = date_utils::get_zodiac(3, 15);
    println!("3月15日星座: {}", zodiac);
    
    // 月份天数
    println!("2024年2月天数: {}", date_utils::days_of_month(2024, 2));
    
    // 日期格式化
    println!("今天日期(YYYY-MM-DD): {}", date_utils::today_yyyy_mm_dd());
    println!("今天时间(HH:MM:SS): {}", date_utils::today_hh_mm_ss());
    
    println!();
}

#[cfg(feature = "validation")]
fn demo_validation_features() {
    println!("【验证功能演示】");
    
    use librarys::core::validation;
    
    // 基本验证
    println!("is_email('test@example.com'): {}", validation::is_email("test@example.com"));
    println!("is_phone('13812345678'): {}", validation::is_phone("13812345678"));
    println!("is_url('https://www.example.com'): {}", validation::is_url("https://www.example.com"));
    
    // 数字验证
    println!("is_integer('123'): {}", validation::is_integer("123"));
    println!("is_float('3.14'): {}", validation::is_float("3.14"));
    println!("is_positive_integer('42'): {}", validation::is_positive_integer("42"));
    
    // 中文验证
    println!("is_chinese('你好世界'): {}", validation::is_chinese("你好世界"));
    println!("is_real_name('张三'): {}", validation::is_real_name("张三"));
    
    // 掩码处理
    println!("mask_phone('13812345678'): {}", validation::mask_phone("13812345678"));
    println!("mask_id_card('123456789012345678'): {}", validation::mask_id_card("123456789012345678"));
    
    // UUID生成
    println!("UUID: {}", validation::generate_uuid());
    
    println!();
}

#[cfg(feature = "crypto")]
fn demo_crypto_features() {
    println!("【加密功能演示】");
    
    use librarys::crypto;
    
    let text = "Hello, Rust!";
    
    // 哈希算法
    println!("MD5('{}') = {}", text, crypto::md5_hash(text));
    println!("SHA1('{}') = {}", text, crypto::sha1_hash(text));
    println!("SHA256('{}') = {}", text, crypto::sha256_hash(text));
    
    // Base64编码（使用base64库）
    use base64::{Engine as _, engine::general_purpose};
    let encoded = general_purpose::STANDARD.encode(text);
    println!("Base64编码: {}", encoded);
    let decoded = String::from_utf8(general_purpose::STANDARD.decode(&encoded).unwrap()).unwrap();
    println!("Base64解码: {}", decoded);
    
    // HMAC签名
    if let Ok(signature) = crypto::hmac_sha256(text, "secret_key") {
        println!("HMAC-SHA256签名: {}", signature);
    }
    
    println!();
}

#[cfg(feature = "data")]
fn demo_data_features() {
    println!("【数据处理功能演示】");
    
    use librarys::data::json_utils;
    use serde_json::json;
    
    // 创建示例数据
    let json_str = r#"{"name":"张三","age":30,"city":"北京","hobbies":["读书","游泳","编程"]}"#;
    let json_obj = json!({
        "name": "张三",
        "age": 30,
        "city": "北京",
        "hobbies": ["读书", "游泳", "编程"]
    });
    
    // 格式化JSON
    println!("原始JSON: {}", json_str);
    if let Ok(pretty) = json_utils::prettify_json(json_str) {
        println!("美化JSON:");
        println!("{}", pretty);
    }
    
    // 最小化JSON
    if let Ok(minified) = json_utils::minify_json(json_str) {
        println!("最小化JSON: {}", minified);
    }
    
    // 获取值
    if let Some(name) = json_utils::get_string(&json_obj, "name") {
        println!("姓名: {}", name);
    }
    if let Some(age) = json_utils::get_i64(&json_obj, "age") {
        println!("年龄: {}", age);
    }
    
    // 验证JSON
    println!("是否为有效JSON: {}", json_utils::is_valid_json(json_str));
    
    println!();
}

#[cfg(feature = "random")]
fn demo_random_features() {
    println!("【随机生成功能演示】");
    
    use librarys::random::generators;
    
    // 随机字符串
    println!("随机数字字符串: {}", generators::random_numbers(8));
    println!("随机字母字符串: {}", generators::random_letters(10));
    
    let alphanumeric_chars: Vec<char> = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".chars().collect();
    println!("随机混合字符串: {}", generators::random_string_from_chars(&alphanumeric_chars, 12));
    
    // 随机数字
    println!("随机整数(1-100): {}", generators::random_int_range(1, 100));
    println!("随机浮点数(0.0-1.0): {:.3}", generators::random_float_range(0.0, 1.0));
    println!("随机布尔值: {}", generators::random_bool());
    
    // UUID
    println!("UUID: {}", generators::random_uuid());
    println!("带连字符的UUID: {}", generators::random_uuid_with_hyphens());
    
    // 中文字符
    println!("随机中文字符: {}", generators::random_chinese_char());
    println!("随机中文字符串: {}", generators::random_chinese_string(5));
    
    // 密码生成
    let password = generators::random_password(12);
    println!("随机密码: {}", password);
    
    // 十六进制字符串
    println!("随机十六进制字符串: {}", generators::random_hex_string(16));
    
    println!();
}

#[cfg(feature = "io")]
fn demo_io_features() {
    println!("【IO功能演示】");
    
    use librarys::io::file_utils;
    
    // 文件路径处理
    let file_path = "test/example.txt";
    println!("文件名: {}", file_utils::get_filename(file_path));
    if let Some(ext) = file_utils::get_file_extension(file_path) {
        println!("文件扩展名: {}", ext);
    }
    
    // 文件大小格式化
    println!("1024 bytes = {}", file_utils::format_file_size(1024));
    println!("1048576 bytes = {}", file_utils::format_file_size(1048576));
    println!("1073741824 bytes = {}", file_utils::format_file_size(1073741824));
    
    // 检查文件是否存在（演示）
    println!("文件存在性检查: file_exists() 函数可用");
    
    println!();
}

#[cfg(feature = "network")]
fn demo_network_features() {
    println!("【网络功能演示】");
    
    use librarys::network::http_utils;
    
    // HTTP功能
    println!("网络功能已启用，可以进行HTTP请求");
    
    println!();
}